/**
** @author cjd  
* @date 2018年5月7日  
* @version 1.0  
 */
package com.coconet.gas.until;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * @author Cocnet
 *
 */
public class OtdrFileIn {
	
	public void readSor(List<List<Double>> resultli,InputStream fis) throws IOException {
		
		
		LimitQueue<Integer> lqueue = new LimitQueue<Integer>(8);

		 LimitQueue<Integer> fxparamquque = new LimitQueue<Integer>(16);
		 LimitQueue<Integer> fxparam_zeroquque = new LimitQueue<Integer>(8);
		int temp = 0;
		int len = 0;// 每次读取到的数据的长度
		List<Integer> li = new ArrayList<Integer>(4);
		List<Integer> fxparam = new ArrayList<Integer>(16);

		int op = 0;
		Long juli = 0L;
		while ((temp = fis.read()) != -1) {
			len++;
			fxparamquque.offer(temp);
			lqueue.offer(temp);
			fxparam_zeroquque.offer(temp);
			Iterator iter = lqueue.iterator();
			Iterator iter_fxparam = fxparamquque.iterator();
			Iterator iter_fxparam_zero = fxparam_zeroquque.iterator();
			StringBuffer sb = new StringBuffer();
			StringBuffer sb_sparam = new StringBuffer();
			StringBuffer sb_sparam_zero = new StringBuffer();
//			while (iter_fxparam_zero.hasNext()) {
//				// 如果存在，则调用next实现迭代
//				// Object-->Integer-->int
//				int j = (int) iter_fxparam_zero.next(); // 把Object型强转成int型
//				char ch = (char) j;
//				sb_sparam_zero.append(ch);
//			}
//			while (iter_fxparam.hasNext()) {
//				// 如果存在，则调用next实现迭代
//				// Object-->Integer-->int
//				int j = (int) iter_fxparam.next(); // 把Object型强转成int型
//				char ch = (char) j;
//				sb_sparam.append(ch);
//			}
			while (iter.hasNext()) {
				// 如果存在，则调用next实现迭代
				// Object-->Integer-->int
				int j = (int) iter.next(); // 把Object型强转成int型
				char ch = (char) j;
				sb.append(ch);
			}
			
			if (len>260&&len<=264) {
				fxparam.add(temp);
			}
			
			
			if (sb.toString().equals("DataPts\0")) {
				op++;
				if (op == 2) {
					// li.add(temp);
					Collections.reverse(fxparam);
					for (int j = 0; j < fxparam.size(); j++) {

						juli += ((int) fxparam.get(j) & 0xff) << ((3 - j) * 8);
					}
					
					break;
				}
			}

		}
		int q = 0;
		while ((temp = fis.read()) != -1) {
			q++;
			li.add(temp);
			if (q == 4) {
				break;
			}
			// System.out.println(temp);
		}

		Collections.reverse(li);
		Long inter = 0L;
		for (int j = 0; j < li.size(); j++) {

			inter += ((int) li.get(j) & 0xff) << ((3 - j) * 8);
		}

		List<Integer> xy = new ArrayList<Integer>(2);			
		Long num = (long) -8.0;
		double result = 0L;
		double counter = 0L;
		while ((temp = fis.read()) != -1 && num < inter*2) {
			num++;
			if (num>0) {
				xy.add(temp);
				if (xy.size() == 2) {
					Collections.reverse(xy);
					for (int p = 0; p < xy.size(); p++) {
						result += ((int) xy.get(p) & 0xff) << ((1 - p) * 8);
					}
					counter++;
					List<Double> resultop = new ArrayList<Double>();
					resultop.add((counter/inter)*(juli/10));
					
					resultop.add((-result/1000));
					resultli.add(resultop);
					result = 0L;
					xy.clear();
				}
			}
			
		}
		
	}

	
}
